package com.situ.day2;

import org.junit.Test;

import java.util.Scanner;

public class WhileForSwitchDemo {

    /*
    循环的三要素：
    1、循环条件的初始化
    2、循环条件的控制
    3、循环条件的改变*/
    @Test
    public void test1() {
        // while、for
        int i = 1;
        while (i <= 5) {
            System.out.println("HelloWorld");
            i++;
        }
    }

    @Test
    public void test2() {
        for (int i = 1; i <= 5; i++) {
            System.out.println("HelloWorld");
        }
    }

    //1、累加思想（1+2+3+... + 100）
    //sum += i;     sum = sum + i
    //sum -= i;     sum = sum - i
    //sum *= i;     sum = sum * i
    //sum /= i;     sum = sum / i
    @Test
    public void test3() {
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            System.out.println(i);
            sum += i;//sum = sum + i;
            System.out.println("sum: " + sum);
        }
        System.out.println("sum: " + sum);
    }

    //统计思想，数一下符合条件的有多少个（计算1-100以内7的倍数的个数）
    @Test
    public void test7() {
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 7 == 0) {
                System.out.println(i);
                count++;
            }
        }
        System.out.println("count: " + count);
    }

//    ****
//    ****
//    ****
    @Test
    public void test56() {
        //****
        for (int i = 1; i <= 4; i++) {
            System.out.print("*");
        }
        System.out.println();
        //*
        //*
        //*
        //*
        for (int i = 1; i <= 4; i++) {
            System.out.println("*");
        }
    }

//    ****
//    ****
//    ****
    @Test
    public void test99() {
        for (int i = 1; i <= 3; i++) {
            //i=1代表打印第一行
            for (int j = 1; j <= 4; j++) {
                System.out.print("*");
            }
            //打印完一行之后换行
            System.out.println();
        }
    }

//    *
//    **
//    ***
//    ****
//    *****
    @Test
    public void test86() {
        //i=1  j=1
        //i=2  j=2
        //i=3  j=3
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    @Test
    public void test19() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                //System.out.print("2*7=14\t");
                System.out.print(j + "*" + i + "=" + (i * j) + "\t");
            }
            System.out.println();
        }
    }

    @Test
    public void test90() {
        int num = 2;
        if (num == 1) {
            System.out.println("1");
        } else if (num == 2) {
            System.out.println("2");
        } else if (num == 3) {
            System.out.println("3");
        } else {
            System.out.println("else");
        }

        switch (num) {
            case 1:
                System.out.println("1");
                break;
            case 2:
                System.out.println("2");
                break;
            case 3:
                System.out.println("3");
                break;
            default:
                System.out.println("default");
                break;
        }
    }

    @Test
    public void test156() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入月份：");
        int month = scanner.nextInt();
        switch (month) {
            case 1:
                System.out.println("31天");
                break;
            case 2:
                System.out.println("28/29天");
                break;
            case 3:
                //Duplicate branch in 'switch'
                System.out.println("31天");
                break;
            case 4:
                System.out.println("30天");
                break;
            case 5:
                System.out.println("31天");
                break;
            case 6:
                System.out.println("30天");
                break;
            default:
                System.out.println("default");
                break;
        }
    }

    @Test
    public void test10() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入月份：");
        int month = scanner.nextInt();
        if (month < 0 || month > 12) {
            System.out.println("月份非法");
            return;
        }

        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                System.out.println("31天");
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                System.out.println("30天");
                break;
            case 2:
                System.out.println("28/29天");
                System.out.println("请输入年份");
                int year = scanner.nextInt();
                if ((year % 4 == 0 && year % 100 != 0) || (year % 400 ==0)) {
                    System.out.println("29天");
                } else {
                    System.out.println("28天");
                }
                break;
            default:
                System.out.println("default");
                break;
        }
    }


}
